package com.zone.editor;

import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.zone.editor.inter.EditorView;
import com.zone.editor.inter.EditorViewState;
import com.zone.editor.photoEditor.R;

public class BoxHelper {
    private final EditorView parentView;
    private final EditorViewState mViewState;

    public BoxHelper(EditorView parentView, EditorViewState viewState) {
        this.parentView = parentView;
        mViewState = viewState;
    }

    public void clearHelperBox() {
        for (int i = 0; i < parentView.getChildCount(); i++) {
            View childAt = parentView.getChildAt(i);
            FrameLayout frmBorder = childAt.findViewById(R.id.frmBorder);
            if (frmBorder != null) {
                frmBorder.setBackgroundResource(0);
            }
            ImageView imgClose = childAt.findViewById(R.id.imgPhotoEditorClose);
            if (imgClose != null) {
                imgClose.setVisibility(View.GONE);
            }
        }
        mViewState.clearCurrentSelectedView();
    }

    public void clearAllViews(View drawingView) {
        for (int i = 0; i < mViewState.getAddedViewsCount(); i++) {
            parentView.removeView(mViewState.getAddedView(i));
        }
        if (mViewState.containsAddedView(drawingView)) {
            parentView.addView(drawingView);
        }
        mViewState.clearAddedViews();
        mViewState.clearRedoViews();

        if (parentView != null)
            parentView.clearAll();
    }
}
